
//------------------------------------------------------------------------------

using Apps.Models;
using Apps.IDAL.CY;
using System;
using System.Linq;

namespace Apps.DAL.CY
{
	public partial class CY_INSTOCK_DETAILRepository:BaseRepository<CY_INSTOCK_DETAIL>,ICY_INSTOCK_DETAILRepository,IDisposable
	{
	    public CY_INSTOCK_DETAILRepository(DBContainer db):base(db)
        {
        
        }

        public IQueryable<CY_INSTOCK_DETAILModel> QueryInstockDetailList()
        {
            IQueryable<CY_INSTOCK_DETAILModel> list = from a in Context.CY_INSTOCK_DETAIL
                                                      join b in Context.CY_INSTOCK on a.INSTOCK_ID equals b.INSTOCK_ID into stock
                                                      from tb in stock.DefaultIfEmpty()
                                                      join c in Context.V_RC_WEIGHING on a.DETAIL_ID equals c.DETAIL_ID into weighing
                                                      from tc in weighing.DefaultIfEmpty()
                                                      join d in Context.SysUser on tb.INSTOCK_USER equals d.UserName into tuser
                                                      from td in tuser.DefaultIfEmpty()
                                                      join p in Context.PUB_CY_STOCKPILE on a.STOCKPILE_ID equals p.STOCKPILE_ID into pcs
                                                      from tp in pcs.DefaultIfEmpty()
                                                      select new CY_INSTOCK_DETAILModel()
                                                      {
                                                          DETAI_ID = a.DETAI_ID,
                                                          INSTOCK_ID = a.INSTOCK_ID,
                                                          DETAIL_ID = a.DETAIL_ID,
                                                          TOTAL = a.TOTAL,
                                                          STOCKPILE_ID = a.STOCKPILE_ID,
                                                          COALYARD_AMOUNT = a.COALYARD_AMOUNT,
                                                          OTHER_AMOUNT = a.OTHER_AMOUNT,
                                                          IS_CALC = a.IS_CALC,
                                                          CALC_TIME = a.CALC_TIME,
                                                          INSTOCK_DATE = tb.INSTOCK_DATE,
                                                          TODAY_TOTAL = tb.TOTAL,
                                                          TODAY_COALYARD_AMOUNT = tb.COALYARD_AMOUNT,
                                                          TODAY_OTHER_AMOUNT = tb.OTHER_AMOUNT,
                                                          INSTOCK_USER = tb.INSTOCK_USER,
                                                          INSTOCK_TIME = tb.INSTOCK_TIME,
                                                          BATCH_CODE = tc.BATCH_CODE,
                                                          MINE_NAME = tc.MINE_NAME,
                                                          MATERIEL_NAME = tc.MATERIEL_NAME,
                                                          SUPPLIER_NAME = tc.SUPPLIER_NAME,
                                                          BALANCE = tc.BALANCE,
                                                          INSTOCK_USER_Name=td.TrueName,
                                                          PARTITION_ID=tp.PARTITION_ID
                                                      };
            return list;
        }

        public IQueryable<CY_INSTOCK_DETAILModel> QueryDetailList()
        {
            IQueryable<CY_INSTOCK_DETAILModel> list = from a in Context.CY_INSTOCK_DETAIL
                                                      join p in Context.PUB_CY_STOCKPILE on a.STOCKPILE_ID equals p.STOCKPILE_ID into pcs
                                                      from tp in pcs.DefaultIfEmpty()
                                                      select new CY_INSTOCK_DETAILModel()
                                                      {
                                                          DETAI_ID = a.DETAI_ID,
                                                          INSTOCK_ID = a.INSTOCK_ID,
                                                          DETAIL_ID = a.DETAIL_ID,
                                                          TOTAL = a.TOTAL,
                                                          STOCKPILE_ID = a.STOCKPILE_ID,
                                                          COALYARD_AMOUNT = a.COALYARD_AMOUNT,
                                                          OTHER_AMOUNT = a.OTHER_AMOUNT,
                                                          IS_CALC = a.IS_CALC,
                                                          CALC_TIME = a.CALC_TIME,
                                                          PARTITION_ID = tp.PARTITION_ID
                                                      };
            return list;
        }

        public IQueryable<V_CY_INSTOCK_DETAIL> QueryList()
        {
            return Context.V_CY_INSTOCK_DETAIL;
        }
    }
}
